package com.gzist.elderlyserviceplatform.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.ListQueryPageDTO;
import com.gzist.elderlyserviceplatform.entity.po.ElderlyService;
import com.gzist.elderlyserviceplatform.service.ElderlyServiceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 养老服务表
 */
@RestController
@Tag(name = "养老服务管理")
@RequestMapping("/api/admin/elderlyService")
@RequiredArgsConstructor
public class ElderlyServiceControllerA {
    private final ElderlyServiceService elderlyServiceService;

    @PostMapping("/add")
    @Operation(summary = "养老服务信息发布")
    public Result add(@RequestBody ElderlyService elderlyService) {
        elderlyServiceService.save(elderlyService);
        return Result.success("添加成功");
    }

    @PostMapping("/list")
    @Operation(summary = "养老服务信息查询")
    public Result<Page<ElderlyService>> list(@RequestBody @Parameter(name = "查询参数") ListQueryPageDTO listQueryPageDTO) {
        return Result.success(elderlyServiceService.list(listQueryPageDTO), "查询成功");
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "养老服务信息单个查询")
    public Result<ElderlyService> detail(@PathVariable @Parameter(name = "养老服务主键") String id) {
        return Result.success(elderlyServiceService.getById(id), "查询成功");
    }

    @PostMapping("/update")
    @Operation(summary = "养老服务信息修改")
    public Result update(@RequestBody @Parameter(name = "服务信息") ElderlyService elderlyService) {
        elderlyServiceService.update(elderlyService);
        return Result.success("修改成功");
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "养老服务信息删除")
    public Result delete(@PathVariable @Parameter(name = "养老服务主键") String id) {
        elderlyServiceService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "养老服务信息批量删除")
    public Result batchDelete(@RequestBody @Parameter(name = "养老服务主键集") String[] ids) {
        elderlyServiceService.removeByIds(Arrays.asList(ids));
        return Result.success("批量删除成功");
    }
}

